<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    var longestConsecutive = function(nums) {
        if(nums.length==0)return 0
        nums.sort((a,b)=>a-b);
        let res = 1;
        let max = 1;
        for(let i = 0;i<nums.length-1;i++){
            if(nums[i]==nums[i+1]){
                continue
            }else if(nums[i+1] == nums[i]+1)
             {
                res++
                max = max < res?res:max
            }else{
                res=1
            }
        }
        return max;
    };

    let nums = [0,3,7,2,5,8,4,6,0,1]
    console.log(longestConsecutive(nums))
    console.log(nums.length)
</script>